<%--
    Document   : create fragment for add relationship
    Created on : Mar 10, 2014, 10:54:45 PM
    Author     : Anton Strack
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<div class="csd_content_form">
    <form method="POST" action="${config.getPath()}">
        <div class="form-group">
            <label class="form-control" for="postA">${postATypeName}</label>
            <p>Select the ${postATypeName} that has the relationship.</p>
            <select class="form-control" id="postA" name="postA">
                <c:forEach items="${aPosts}" var="aPost" >
                    <c:choose>
                        <c:when test="${postATypeId == primaryTypeId}">
                            <c:if test="${aPost.id == primaryId}">
                                <%-- only show the id of the primary resource since the user is adding to that resource. --%>
                                <option value="${aPost.id}">${aPost.name}</option>
                            </c:if>
                        </c:when>
                        <c:otherwise>
                            <option value="${aPost.id}">${aPost.name}</option>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
            </select><br />
            <label class="form-control" for="relationships">Relationship</label>
            <p>Select the relationship between the ${postATypeName} and ${postBTypeName}.</p>
            <select class="form-control" id="relationshipId" name="relationshipId">
                <c:forEach items="${beans}" var="bean" >
                    <option value="${bean.id}" title="${bean.description}">${bean.name}</option>
                </c:forEach>
            </select><br />
            <input type="hidden" name="resourceTypeId" id="resourceTypeId" value="${resourceTypeId}" />
            <label class="form-control" for="postB">${postBTypeName}</label>
            <p>Select ${postBTypeName} that is related to the ${postATypeName}</p>
            <select class="form-control" id="postB" name="postB">
                <c:forEach items="${bPosts}" var="bPost" >
                    <c:choose>
                        <c:when test="${postBTypeId == primaryTypeId && postATypeId != primaryTypeId}">
                            <c:if test="${bPost.id == primaryId}">
                                <%-- only show the id of the primary resource since the user is adding to that resource. --%>
                                <option value="${bPost.id}">${bPost.name}</option>
                            </c:if>
                        </c:when>
                        <c:otherwise>
                            <option value="${bPost.id}">${bPost.name}</option>
                        </c:otherwise>
                    </c:choose>
                </c:forEach>
            </select><br />
            <input type="hidden" name="primaryTypeId" id="primaryTypeId" value="${primaryTypeId}" />
            <input type="hidden" name="primaryId" id="primaryId" value="${primaryId}" />
        </div>
        <button class="btn btn-primary" name="formSubmit" id="formSubmit" value="add-relationship" type="submit">Add to ${postTypeName}</button>
    </form>
</div>

